package com.example.qsaqmq.controller;


import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.*;


@RestController
@CrossOrigin
@RequestMapping("/Api")
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * Get请求成功并返回success
     * @param bedroom
     * @param electric
     * @return
     */
    @GetMapping("/query")
    public String sendDirectMessage(@RequestParam("bedroom") String bedroom,@RequestParam("tower") String tower,@RequestParam("floor") String floor, @RequestParam("electric") Double electric, @RequestParam("power") Double power, @RequestParam("violations") boolean flag , @RequestParam("day") String reviceDate,@RequestParam("time") String time1) {
        Map<String,Object> map = new HashMap<>();
        map.put("bedroom",bedroom);
        map.put("electric",electric);
        map.put("power",power);
        map.put("violations",flag);
        String time2 = reviceDate+" "+time1;
        map.put("time",time2);
        map.put("tower",tower);
        map.put("floor",floor);
        rabbitTemplate.convertAndSend("TestRabbitDirectExchange","TestDirectRouting",map);
        System.out.println(map);
        return "success";
    }

//    @GetMapping("/asd")
//    public String sda(@RequestParam("aa") String a,@RequestParam("bb") Double as,@RequestParam("ee") Double asd,@RequestParam("dd") Boolean flag,@RequestParam("ff") String sa,@RequestParam("rr") String asdd){
//        System.out.println(a);
//        System.out.println(as);
//        System.out.println(asd);
//        System.out.println(flag);
//        System.out.println(sa+" "+asdd);
//        return "success";
//    }
}
